import { requestModel, registerEntityType } from '../base'
import { registerEntityTable } from '../table'
import type { AircraftType } from './types'
import { setupAircraftTypeView, showAircraftTypeView } from './view'
import AircraftTypeFilterVue from './AircraftTypeFilter.vue'

export * from './types'

export {
  type FlightPerformance,
  type FlightPerformanceTable,
  getFlightPerformanceTable,
  getFlightPerformanceTableById
} from './flight-performance'

export {
  type ClimbProfile,
  type ClimbProfileItem,
  getClimbProfile,
  getClimbProfileById
} from './climb-profile'

export {
  type DescentProfile,
  type DescentProfileItem,
  getDescentProfile,
  getDescentProfileById
} from './descent-profile'

export { showAircraftTypeView, selectAircraftTypeView } from './view'

function setupAircraftTypeTable() {
  registerEntityTable<AircraftType>({
    type: 'AircraftType',
    columns: [
      {
        name: 'id',
        cell: (e) => e.id,
        width: 100
      },
      {
        name: '类型',
        cell: (e) => e.wakeTurbulenceCategory,
        width: 100
      },
      {
        name: '引擎类型',
        cell: (e) => e.engineType,
        width: 100
      },
      {
        name: '引擎数量',
        cell: (e) => e.engineCount,
        width: 100
      }
    ],
    filter: AircraftTypeFilterVue,
    onDClick: showAircraftTypeView
  })
}

export async function setupAircraftType() {
  const data = (await requestModel('AircraftType')) as AircraftType[]
  registerEntityType<AircraftType>({
    type: 'AircraftType',
    typeName: '机型',
    data
  })
  setupAircraftTypeTable()
  setupAircraftTypeView()
}
